#ifndef _AI_H_
#define _AI_H_

#include "Physics.h"
#include "Boid.h"
#include "Map.h"
#include "BoidCollisionEvent.h"

/**
Ai maintains all algoritms of artificial intelligence
*/
class Ai
{
public:
	Ai();
	virtual ~Ai();

	/**
	inits virtual scene for AI
	*/
	void Init(Physics* scene, Map *map, int border);

	/**
	simulates behavior of boids
	*/
	void Maintain(Physics *scene, float time);

	/**
	Adds new boid to scene
	*/
	void AddBoid(Boid* boid);

	/**
	destroys AI's scene
	*/
	void Destroy(void);

	/**
	removes boid from scene
	*/
	void RemoveBoid(Boid* boid);

	/**
	returns a pointer to the list with eaten boids
	*/
	list<DynamicSphere*>* EatenBoids(void);

private:
	list<Boid*> boids;	
	list<Boid*>* map;
	int mapX, mapY, mapZ;
	int border;	
	static int fieldSize;
	static int mapXmulFieldSize, mapYmulFieldSize, mapZmulFieldSize;
	BoidCollisionEvent boidCollisionHandler;	

	bool IsInsideScene(float x, float y, float z);	
	list<Boid*>* MapField(float x, float y, float z);
	void MaintainBoid(Boid* boid, float time, Physics *scene);
	Vector3 AvoidCollision(Boid *boid, Physics *scene);
	void FindVisibleBoids(Boid *boid, list<list<Boid*>*>* boidLists, list<Boid*>* visibleBoids);
	void MaintainYellow(Boid *boid, list<Boid*>* boids, Vector3 &collision, float time);
	void MaintainRed(Boid *boid, list<Boid*>* boids, Vector3 &collision, float time);
};

#endif